for i in [1 2 3 4 5 6]
  match $((i % 2))
    case 0; echo "Even!"
    case 1; echo "Odd!" 
  end
end

let out1 = "/foo/bar/baz.tar.gz: application/x-gzip";
let out2 = "/foo/bar/baz.quxx: application/quxx-archive";

fn analyze output
  match @split(output)[1]
    case application/x-gzip; echo "Use tar -xzf"
    case _ ; echo "Unknown file type"
  end
end

analyze $out1
analyze $out2

fn analyze_regex output
  match output
    case ".*application/x-gzip"; echo "Use tar -xzf"
    case _ ; echo "Unknown file type"
  end
end

analyze $out1
analyze $out2

fn wildcard input
  match $input
    case _; echo "WILDCARD!"
    case huh; echo "U N R E A C H A B L E"
  end
end

wildcard "FOOOOO"
wildcard "huh"

fn report usage
  match $usage
    case @(seq 0 25); echo "Plenty of space my guy"
    case @(seq 26 50); echo "Almost half full (or half empty)"
    case @(seq 51 75); echo "Getting close to full :O"
    case @(seq 76 99); echo "Time for spring cleaning, almost full!"
    case _; echo "How did you even do this..."
  end
end

report 37
report 55
report 98
report FOOOO

fn animated filetype
  match $filetype
    case ["image/jpeg" "image/png"]
      echo "Static :("
    case "image/gif"
      echo "Animated :D"
  end
end

animated "image/jpeg"
animated "image/png"
animated "image/gif"

fn in_range min max val
  if test $min -gt $max
    let min max = $max $min
  end
  match $val
    case @(seq $min $max);
      if test $val -eq $min
        echo "$val at minimum"
      else if test $val -eq $max
        echo "$val at maximum"
      else
        echo "$val is between $min and $max"
      end
    case _
      if test $val -lt $min
        echo "$val is less than min=$min"
      else
        echo "$val is more than max=$max"
      end
  end
end

in_range 0 10 5
in_range 0 10 0
in_range 0 10 10
in_range 1 10 0
in_range 0 9  10
